package com.moss.cloud.base.biz.controller;

import com.moss.cloud.base.api.model.from.BaseFrom;
import com.moss.cloud.base.api.model.from.GatewayRoutesFrom;
import com.moss.cloud.base.api.model.param.GatewayRouteQueryParam;
import com.moss.cloud.base.biz.service.IGatewayRoutesService;
import com.moss.cloud.common.core.constant.ServiceList;
import com.moss.cloud.common.core.model.Result;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping(ServiceList.BASE + "/gatewayRoutes")
public class GatewayRoutesController {
    private IGatewayRoutesService gatewayRoutesService;

    public GatewayRoutesController(IGatewayRoutesService gatewayRoutesService) {
        this.gatewayRoutesService = gatewayRoutesService;
    }

    /**
     * 获取网关路由
     *
     * @param gatewayRouteQueryParam 搜索参数
     * @Author: 瑾年
     * @Date: 2023年10月21日
     */
    @PostMapping("/query")
    public Result<?> query(@RequestBody GatewayRouteQueryParam gatewayRouteQueryParam) {
        return Result.success(gatewayRoutesService.query(gatewayRouteQueryParam));
    }

    /**
     * 获取网关路由
     *
     * @param gatewayRouteQueryParam 搜索参数
     * @Author: 瑾年
     * @Date: 2023年10月21日
     */
    @PostMapping("/routesPages")
    public Result<?> routesPages(@RequestBody GatewayRouteQueryParam gatewayRouteQueryParam) {
        return Result.success(gatewayRoutesService.routesPages(gatewayRouteQueryParam));
    }

    /**
     * 新增网关路由
     *
     * @param gatewayRoutesFrom 网关路由对象
     * @Author: 瑾年
     * @Date: 2023年10月21日
     */
    @PostMapping("/save")
    public Result<?> save(@RequestBody @Validated GatewayRoutesFrom gatewayRoutesFrom) {
        return Result.success(gatewayRoutesService.add(gatewayRoutesFrom));
    }

    /**
     * 修改网关路由
     *
     * @param gatewayRoutesFrom 网关路由对象
     * @Author: 瑾年
     * @Date: 2023年10月21日
     */
    @PostMapping("/update")
    public Result<?> update(@RequestBody @Validated GatewayRoutesFrom gatewayRoutesFrom) {
        return Result.success(gatewayRoutesService.update(gatewayRoutesFrom));
    }

    /**
     * 删除网关路由
     *
     * @param baseFrom
     * @Author: 瑾年
     * @Date: 2023年10月21日
     */
    @PostMapping("/delete")
    public Result<?> delete(@RequestBody @Validated BaseFrom baseFrom) {
        return Result.success(gatewayRoutesService.delete(baseFrom));
    }

    /**
     * 加载网关路由配置
     *
     * @Author: 瑾年
     * @Date: 2020-4-23
     */
    @PostMapping("/overload")
    public Result<?> overload() {
        return Result.success(gatewayRoutesService.overload());
    }
}
